package com.bilibili.juc.locks;

import java.util.concurrent.TimeUnit;

class MyPhone //资源类
{
    public  synchronized void sendEmail()
    {
       // try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
        System.out.println("-----sendEmail");
    }

    public  synchronized void sendSMS()
    {
        System.out.println("-----sendSMS");
    }

    public void hello()
    {
        System.out.println("-------hello()");
    }
}

class TTThone{

    public   void sendEmail() {
        synchronized (TTThone.class) {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("------sendEmail()-------");
        }
    }
    public    void sendSMS(){
        synchronized (TTThone.class) {
            System.out.println("------sendSMS()-------");
        }
    }
    public void hello() {
        System.out.println("-------hello()");
    }



}


public class SycLock8Demo {
    public static void main(String[] args) {
        TTThone phone1 = new TTThone();
        TTThone phone2 = new TTThone();
        new Thread(
                ()->{
                    phone1.sendEmail();
                }, "a"
        ).start();

        //try { TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); }

        new Thread(
                ()->{
                    phone2.sendSMS();
                    //phone2.hello();
                }, "B"
        ).start();
    }
}
